public class Leetcode942 {
    public int[] diStringMatch(String s) {
        int n = s.length();
        int[] res = new int[n + 1];
        int currentMin = 0, currentMax = n;

        char[] sChars = s.toCharArray();
        for (int index = 0; index < n; index++) {
            if (sChars[index] == 'I') {
                res[index] = currentMin++;
            } else {
                res[index] = currentMax--;
            }
        }

        res[n] = currentMin;
        return res;
    }
}
